package com.linkage.educloud.ah.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

import com.linkage.educloud.ah.bean.ResClassify;
import com.linkage.educloud.ah.util.ImageLoader;
import com.zzhou.common.library.util.ToastShow;

import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/18.
 */

public class AppMainResAdapter extends android.widget.BaseAdapter {
    private Context mContext;
    private List<ResClassify> mList;

    public AppMainResAdapter(Context context, List<ResClassify> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public ResClassify getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ImageView pic = new ImageView(mContext);
        pic.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, 240));
        pic.setScaleType(ImageView.ScaleType.FIT_XY);
        pic.setPadding(8, 0, 8, 0);

        final ResClassify resClassify = mList.get(position);
        ImageLoader.loadImg(mContext, resClassify.getResicon(), pic);
        pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent;
                switch (resClassify.getRestype()) {
                    case 0: // 0 说明是最后一课
                        ToastShow.show(mContext, "最后一课");
//                        intent = new Intent(mContext, WebViewCompaignActivity.class);
//                        intent.putExtra(WebViewCompaignActivity.KEY_URL, classifies.get(position).getCpath());
//                        mContext.startActivity(intent);
                        break;
                    case 1:
                        ToastShow.show(mContext, "1");
//                        intent = new Intent(mContext,
//                                ResourcesActivity.class);
//                        mContext.startActivity(intent);
                        break;
                    case 2:
                        ToastShow.show(mContext, "2");
//                        intent = new Intent(mContext,
//                                LastResourcesActivity.class);
//                        mContext.startActivity(intent);
                        break;
                    case 3:
                        ToastShow.show(mContext, "解密母题");
//                        intent = new Intent(mContext,
//                                DecryptionMotifActivity.class);
//                        intent.putExtra("title", "解密母题");
//                        intent.putExtra("type", 3);
//                        mContext.startActivity(intent);
                        break;
                    case 4:
                        ToastShow.show(mContext, "4");
//                        intent = new Intent(mContext,
//                                PackageListActivity.class);
//                        mContext.startActivity(intent);
                        break;
                    case 5:
                        ToastShow.show(mContext, "解读高考");
//                        intent = new Intent(mContext,
//                                DecryptionMotifActivity.class);
//                        intent.putExtra("title", "解读高考");
//                        intent.putExtra("type", 5);
//                        mContext.startActivity(intent);
                        break;
                }

            }
        });
        return pic;
    }

    public class viewHolder {
        private ImageView pic;
    }
}
